<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>兮家手册--添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">

    <link rel="stylesheet" href="/components/layuiadmin/layui/src/css/layui.css">
    <link rel="stylesheet" href="/components/editor/css/editormd.css">
    <script src="/components/layuiadmin/layui/src/layui.js"></script>
    <script src='/base/js/jquery-3.4.1.min.js'></script>
    <script src="/modules/js/app.js"></script>
    <script type="text/javascript" src="/components/editor/editormd.js"></script>

</head>
<body>
<!-- 置前 -->
<!--<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="position:fixed; z-index:999;display: block;  top:1%; left:1%; text-decoration: none;">-->
<div class="layui-form" lay-filter="layuiadmin-app-form-list" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">标题：</label>
        <div class="layui-input-inline" style="width: 35%">
            <input type="text" id="title" name="title" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline" style="width: 160px">
            <select id="category" name="category" lay-verify="" lay-filter="required"> </select>
        </div>
        <div class="layui-input-inline" style="width: 160px">
            <select id="helpVersion" name="helpVersion" lay-verify="" lay-filter="required"></select>
        </div>
        </select>
        <label class="layui-form-label">排序：</label>
        <div class="layui-input-inline" style="width: 160px">
            <input type="text" id="sort" name="sort" lay-verify="required" value="0" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item layui-hide">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-submit" id="layuiadmin-app-form-submit" value="确认添加">
        <input type="button" lay-submit lay-filter="layuiadmin-app-form-edit" id="layuiadmin-app-form-edit" value="确认编辑">
    </div>
</div>

<div id="L_content"></div>
<script src="/components/editor/imgCopyPull2.js"></script>

<script>

    layui.use(['form'], function () {
        init();
        myEditor2();
    });


    function init() {
        $("#category").html(Dict.getDictSelect(Enums.Xj.HelpCategory));        // 是否跳转  不带默认值
        $("#helpVersion").html(Dict.getDictSelect(Enums.Xj.HelpVersion));      // 位置
        layui.form.render();     // 刷新,否则select可能不生效
    }


    // 主键id
    var id;
    var myEditor;

    function myEditor2() {
        //注意1：这里的就是上面的DIV的id属性值
        myEditor = editormd("L_content", {
            width: "96%",
            height: 860,
            syncScrolling: "single",
            path: "/components/editor/lib/",// 资源路径
            // 自定义的增强配置！
            saveHTMLToTextarea: true,        // 保存 HTML 到 Textarea
            emoji: true, // 开启表情的功能！ 图片的本地配置！
            // theme: "light",               // 工具栏主题
            // previewTheme: "dark",         // 预览主题
            // editorTheme: "pastel-on-dark",// 编辑主题
            // markdown的配置！
            tex: true,                   // 开启科学公式TeX语言支持，默认关闭
            flowChart: true,             // 开启流程图支持，默认关闭
            sequenceDiagram: true,       // 开启时序/序列图支持，默认关闭,
            imageUpload: false,          // 图片本地上传,禁用，使用imgCopyPull2.js 的上传方式
            /*指定需要显示的功能按钮*/
            toolbarIcons: function () {
                return ["undo", "redo", "|",
                    "bold", "del", "italic", "quote", "ucwords", "uppercase", "lowercase", "|",
                    // "h1","h2","h3","h4","h5","h6","|",
                    "list-ul", "list-ol", "hr", "|",
                    "link", "reference-link", "image", "code", "preformatted-text",
                    "code-block", "table", "datetime", "emoji", "html-entities", "pagebreak", "|",
                    "goto-line", "watch", "preview", "fullscreen", "clear", "search", "|",
                    "help", "info", "|",
                    "releaseIcon", "index"]
            },
            /*自定义功能按钮，下面我自定义了2个，一个是发布，一个是返回首页*/
            toolbarIconTexts: {
                releaseIcon: "<span bgcolor=\"gray\">发布文章</span>",
                // index : "<span bgcolor=\"red\">返回首页</span>",
            },
            /*给自定义按钮指定回调函数*/
            toolbarHandlers: {
                releaseIcon: function (cm, icon, cursor, selection) {
                    //表单提交
                    let data = {
                        content: myEditor.getMarkdown(), // $("#L_content").val(),
                        title: $("#title").val(),
                        category: $("#category").val(),
                        helpVersion: $("#helpVersion").val(),
                        sort: $("#sort").val(),
                        id: id,
                    };
                    if (id != null) {
                        // 编辑
                        let result = Ajax.put(path + "/admin/xj/adminHelp/upd", data);
                        id = result.data;
                        layer.msg(result.msg);
                    } else {
                        // 新增
                        let result = Ajax.post(path + "/admin/xj/adminHelp/insert", data);
                        id = result.data;
                        layer.msg(result.msg);
                    }
                },
            }
        });
    }
</script>
</body>
</html>
